package cn.zn.job.service.impl;

import cn.zn.job.entity.SysJobLog;
import cn.zn.job.mapper.SysJobLogMapper;
import cn.zn.job.service.SysJobLogService;
import cn.zn.job.vo.SysJobLogPageVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;

/**
 * <p>
 * 定时任务调度日志表 服务实现类
 * </p>
 *
 * @author zn-admin
 * @since 2021-01-29
 */
@Service
public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog> implements SysJobLogService {

    @Override
    public Object selectJobLogList(SysJobLogPageVo vo) {
        if (!vo.getPage()) {
            return baseMapper.selectJobLogList(vo);
        }

        Page<SysJobLog> page = new Page<>(vo.getCurrent(), vo.getSize());
        return baseMapper.selectJobLogList(page, vo);
    }

    @Override
    @Transactional
    public void insertJobLog(SysJobLog jobLog) {
        baseMapper.insert(jobLog);
    }

    @Override
    public void deleteJobLogByIds(String[] jobLogIds) {
        baseMapper.deleteBatchIds(Arrays.asList(jobLogIds));
    }

    @Override
    public void cleanJobLog(String jobId) {
        QueryWrapper<SysJobLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("job_id", jobId);
        baseMapper.delete(queryWrapper);
    }
}
